package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.Pattern;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.service.FindsorceServicehh;
import com.zr.serviceImpl.FindsorceServiceImplhh;

import net.sf.json.JSONObject;

public class CjczControllerhh extends HttpServlet {
	FindsorceServicehh cjzx=new FindsorceServiceImplhh();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
	doPost(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	req.setCharacterEncoding("utf8");
	resp.setCharacterEncoding("utf8");
    String sname = req.getParameter("snamec");
    //System.out.println(sname);
    String cname=req.getParameter("cname"); 
    //System.out.println(cname);
    Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");  
   
    boolean flag=pattern.matcher(sname).matches();
   
    PrintWriter   pw  =  resp.getWriter();
    if(flag){
    int sid=Integer.parseInt(req.getParameter("snamec"));
    String cj=cjzx.findygscorebyid(sid,"", cname);
    //System.out.println(cj);
    JSONObject js=new JSONObject();
	js.put("cj",cj);
	pw.write(js.toString());
	pw.flush();
	pw.close();
    }else{
    	String cj=cjzx.findygscorebyid(0, sname, cname);
    	
    	JSONObject js=new JSONObject();
    	js.put("cj", cj);
    	pw.write(js.toString());
    	pw.flush();
    	pw.close();
    }
    
	
	}
}
